package cn.monkey.io.transport.netty.server.codec.protocol.tcp;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.EmptyByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;

import java.util.function.BiPredicate;

public interface TcpServerProtocolPredicate extends BiPredicate<Channel, Object> {
    default boolean test(Channel channel, Object msg) {
        if (channel instanceof SocketChannel socketChannel && msg instanceof ByteBuf byteBuf) {
            return !(byteBuf instanceof EmptyByteBuf) && this.test0(socketChannel, byteBuf);
        }
        return false;
    }

    default boolean test0(SocketChannel serverSocketChannel, ByteBuf byteBuf) {
        return true;
    }
}